

jQuery(function ($) {
    var user = JSON.parse(localStorage.getItem('user_info')) || {};
    var token = user.token;
    $.ajax({
        type: 'get', //提交方法是POST
        url: host + '/api/nav/getNavInformation',
        contentType: "application/json",
        xhrFields: {
            withCredentials: true
        },
        beforeSend: function beforeSend(request) {
            request.setRequestHeader("X-AUTH-TOKEN", token);
        },
        error: function error(_error) {
            //请求失败的回调方法 
            alert('网络加载失败，请稍候再试!');
        },
        success: function success(result) {
            if (result.code == 200) {
                //渲染每组的属性分类
                var attr = function attr(searchclass, groupListArr) {
                    var fixedGroup = $(searchclass).find('.fixedGroup');
                    var generalizedSort = []; //通用的三组分类
                    for (var f = 0; f < groupListArr.length; f++) {
                        for (var t = 0; t < groupListArr[f].attrList.length; t++) {
                            generalizedSort.push(groupListArr[f].attrList[t]);
                        }
                    }
                    for (var s = 0; s < fixedGroup.length; s++) {
                        var itemDataId = $(fixedGroup[s]).attr('data-id');
                        for (var x = 0; x < generalizedSort.length; x++) {
                            if (itemDataId == generalizedSort[x].group_id) {
                                $(fixedGroup[s]).append('<a href="' + generalizedSort[x].href + '">' + generalizedSort[x].value +  '</a>');
                            }
                        }
                    }
                };

                var html = "";
                var data = result.data;
                var groupList = data[0].groupList;
                var groupListArr = [];
                for (var y = 0; y < data.length; y++) {
                    if (data[y].groupList) {
                        groupListArr.push(data[y].groupList);
                    }
                }

                var itemize = []; //子分类
                var categoryGroupList = []; //类别的分类数组
                for (var i = 0; i < data.length; i++) {
                    html += '  <li class="clearfix isshow" data-id="' + data[i].id + '">\n<strong><a href="' + data[i].url + '" target="_blank">' + data[i].name + '</a></strong></li>';

                    for (var k = 0; k < data[i].sNav.length; k++) {
                        itemize.push(data[i].sNav[k]);
                    };

                    if (data[i].childCats) {
                        for (var u = 0; u < data[i].childCats.length; u++) {
                            categoryGroupList.push(data[i].childCats[u]);
                        }
                    };
                };
                $('.left_ul').html(html);
                $('.noData').remove();
                var parentEl = $('.isshow'); //二级导航
                for (var n = 0; n < parentEl.length; n++) {
                    var parentid = $(parentEl[n]).attr('data-id');
                    for (var j = 0; j < itemize.length; j++) {
                        if (parentid == itemize[j].parent_id) {
                            $(parentEl[n]).append('<a href="' + itemize[j].url + '"><span>' + itemize[j].name + '</span></a>');
                        }
                    }
                };
               
                 $('.isshow').find('a:eq(2)').css('border',0);
            }
        }
    });
    $('.all_sort').mouseenter(function () {
        $('.content_top_left').fadeIn("slow");
    }).mouseleave (function(){
        $('.content_top_left').fadeOut("slow");
    }) 
    
});